﻿using System;
using System.ComponentModel.Design;

namespace CXW.Core.Sharp
{
    /// <summary></summary>
    public abstract class AbstractViewContent : IViewContent
    {
        /// <summary>资源文件资源名称</summary>
        public virtual string Language { set; get; }
        /// <summary>执行参数</summary>
        public virtual string Args { set; get; }
        /// <summary>配置文件名称</summary>
        public virtual string CfgName { set; get; }
        /// <summary>默认 UI 显示文字</summary>
        public virtual string Label { set; get; }
        /// <summary><see cref="Codon.Id"/></summary>
        public virtual string CodonId { set; get; }
        /// <summary>ToolTip提示信息</summary>
        public string InfoTip { set; get; }

        string ResourceServiceLanguage = "";
        /// <summary>要在主窗体显示的控件</summary>
        public abstract object Control
        {
            get;
        }

        /// <summary> IViewContent 对象激活时执行</summary>
        public void ActivateViewContentChanged2()
        {
            if (ResourceServiceLanguage != ResourceService.Language)
            {
                ResourceServiceLanguage = ResourceService.Language;
                OnLanguageChanged();
            }
            ActivateViewContentChanged();
        }
        /// <summary> 显示语言 变更</summary>
        protected virtual void OnLanguageChanged()
        {

        }
        /// <summary> IViewContent 对象激活时执行</summary>
        protected virtual void ActivateViewContentChanged()
        {

        }
        #region IDisposable
        /// <summary>获取一个值，该值指示控件是否已经被释放。</summary>
        /// <remarks>如果控件已经被释放，则为 true；否则为 false。</remarks>
        public bool IsDisposed { get; private set; }
        /// <summary>执行与释放或重置非托管资源相关的应用程序定义的任务</summary>
        public void Dispose()
        {
            IsDisposed = true;
        }
        #endregion

        #region IsActiveViewContent
        /// <summary>
        /// Gets if this view content is the active view content.
        /// </summary>
        protected bool IsActiveViewContent
        {
            get { return WorkbenchSingleton.Workbench != null && WorkbenchSingleton.Workbench.ActivateViewContent == this; }
        }
        #endregion

        #region IServiceProvider
        ServiceContainer services = new ServiceContainer();

        /// <remark/>
        public object GetService(Type serviceType)
        {
            object obj = services.GetService(serviceType);
            if (obj == null)
            {
                if (serviceType.IsInstanceOfType(this))
                    return this;
            }
            return obj;
        }

        /// <remark/>
        public ServiceContainer Services
        {
            get { return services; }
        }

        #endregion
    }
}
